package cn.itcast.bos.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.repository.StandardRepository;
import cn.itcast.bos.service.StandardService;

@Service
@Transactional
public class StandardServiceImpl implements StandardService{
	
	@Autowired
	private StandardRepository standardRepository;

	/**
	 * 新增 收派标准
	 */
	@Override
	public void addStandard(Standard standard) {
		standard.setOperatingTime(new Date());
		standardRepository.save(standard);
	}

	/**
	 * 根据名称查询 收派标准
	 */
	@Override
	public List<Standard> findStandardByName(String name) {
		return standardRepository.findByName(name);
	}
	
	/**
	 * 无条件的分页查询
	 * @return 
	 */
	@Override
	public Page<Standard> findStandardByPage(Pageable pageable){
		Page<Standard> page = standardRepository.findAll(pageable);
		return page;
	}

	/**
	 * 修改 收派标准
	 */
	@Override
	public void updateStandard(Standard standard) {
		standard.setOperatingTime(new Date());
		standardRepository.save(standard);
	}

	/**
	 * 批量删除 收派标准
	 */
	@Override
	public void deleteStandard(String[] idArr) {
		for (String id : idArr) {
			standardRepository.delete(Integer.parseInt(id));
		}
		
	}

	/**
	 * 查找所有的 取派标准
	 */
	@Override
	public List<Standard> findAll() {
		List<Standard> list = standardRepository.findAll();
		return list;
	}
}
